Unit bdrcomon;

{ common functions }

Interface
uses Strings;

{some usefull functions}
Function CleanString(Input : String) : String;
Function MidString(Input : String ; Start, Stop : Byte) : String;
Function LowerCase(Input : String) : String;
Function HiddenString(Input : String) : String;

{ used to create scrambled strings .. }
Function ScrambleString(Input : String) : String;

Implementation

Function CleanString(Input : String) : String;
{clean a string, remove unreadable characters and spaces}
var
  i, j : Byte;
  tmpString : String;
begin
  tmpString := '';
  for i := 1 to Length(Input) do
  begin
    j := Ord(Input[i]);
    if (j >= 33) and (j <= 126) then
      tmpString := tmpString + Input[i];
  end;
  CleanString := tmpString;
end;

Function MidString(Input : String ; Start, Stop : Byte) : String;
Var
  i : Byte;
  tmpString : String;
Begin
  tmpString := '';
  i := Length(Input);

  { incase 'start' parameter is incorrect (too big) }
  If (Start > i) Then Start := i;
  { incase 'stop' parameter is incorrect (too big) }
  If (Stop > i) Then Stop := i;

  For i := Start to Stop do
    tmpString := tmpString + Input[i];

  { return function result }
  MidString := tmpString;
End;

{what the hell is wrong with StrLower from standard Strings unit
 i can't get it to work right! that's why i made this function..}
Function LowerCase(Input : String) : String;
Var
  i, j : Byte;
  tmpString : String;
Begin
  tmpString := '';
  For i := 1 To Length(Input) Do
  Begin
    j := Ord(Input[i]);
    If (j >= 65) And (j <= 90) Then Inc(j, 32);
    tmpString := tmpString + Chr(j);
  End;
  LowerCase := tmpString;
End;

Function HiddenString(Input : String) : String;
{ This function takes a scrambled string and makes it readable again
  This is needed because all strings are stored in the final .EXE file
  and can be found with, for example, a hex editor. Some strings must
  not be readable, such as the credits (people might change them..) and
  the cheat codes (must remain 'secret' codes ). }
Var
  i : Byte;
  tmpString : String;
Begin
  tmpString := '';
  For i := 1 to length(input) Do
   tmpString := tmpString + Chr(Ord(Input[i])-61);

  { return function result }
  HiddenString := tmpString;

End;

Function ScrambleString(Input : String) : String;
{ Scrambles a string, use HiddenString to 'un-scramble' it }
Var
  i : Byte;
  tmpString : String;
Begin

  tmpString := '';

  For i := 1 to length(input) Do
    tmpString := tmpString + Chr(Ord(Input[i])+61);

  { return function result }
  ScrambleString := tmpString;

End;


begin
end.
